package org.sixtynine.stock.entity;

/**
 * @author Thilan
 * this class handle quarterly share data
 */

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;

import org.springframework.format.annotation.NumberFormat;
import org.springframework.format.annotation.NumberFormat.Style;

@Entity
@Table(name = "QUARTERLY_SHARE_DATA")
public class QuarterlyShareData extends BaseEntity {

	private int id;

	@NotNull
	private String quarterCode;

	private double profit;

	@DecimalMin("0.00")
	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double weightedAverage;

	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double averageEquity;

	@DecimalMin("0.00")
	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double averageTotalAsse;

	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double profitAfterTax;

	@DecimalMin("0.00")
	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double revenues;

	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double ebitda;

	@DecimalMin("0.00")
	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double cash;

	@DecimalMin("0.00")
	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double percentOwnbyInsiders;

	@DecimalMin("0.00")
	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double instOwnership;

	@DecimalMin("0.00")
	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double sharesInFreefloat;

	@DecimalMin("0.00")
	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double debt;

	@DecimalMin("0.00")
	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double totShareOutstand;

	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double equityToSharehol;

	private Company company;

	@DecimalMin("0.00")
	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double lstFourQtrWeighted;

	private int year;

	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double adjestedEquityShareholder;

	@DecimalMin("0.00")
	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double adjestedTotalAssets;

	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double recurringNetProfit;

	@DecimalMin("0.00")
	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double currentAssets;

	@DecimalMin("0.00")
	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double currentLiability;

	@NumberFormat(style = Style.NUMBER, pattern = "#,###,###,##0.00")
	private double lstFourQtrRecurringProfit;

	@Id
	@Column(name = "ID", unique = true, nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Column(name = "QUARTER_CODE", nullable = false, length = 100)
	public String getQuarterCode() {
		return quarterCode;
	}

	public void setQuarterCode(String quarterCode) {
		this.quarterCode = quarterCode;
	}

	@Column(name = "PROFIT", length = 100)
	public double getProfit() {
		return profit;
	}

	public void setProfit(double profit) {
		this.profit = profit;
	}

	@Column(name = "WEIGHTED_AVERAGE", length = 100)
	public double getWeightedAverage() {
		return weightedAverage;
	}

	public void setWeightedAverage(double weightedAverage) {
		this.weightedAverage = weightedAverage;
	}

	@Column(name = "AVERAGE_EQUITY", length = 100)
	public double getAverageEquity() {
		return averageEquity;
	}

	public void setAverageEquity(double averageEquity) {
		this.averageEquity = averageEquity;
	}

	@Column(name = "AVERAGE_TOTAL_ASSERTS", length = 100)
	public double getAverageTotalAsse() {
		return averageTotalAsse;
	}

	public void setAverageTotalAsse(double averageTotalAsse) {
		this.averageTotalAsse = averageTotalAsse;
	}

	@Column(name = "PROFIT_AFTER_TAX", length = 100)
	public double getProfitAfterTax() {
		return profitAfterTax;
	}

	public void setProfitAfterTax(double profitAfterTax) {
		this.profitAfterTax = profitAfterTax;
	}

	@Column(name = "REVENUES", length = 100)
	public double getRevenues() {
		return revenues;
	}

	public void setRevenues(double revenues) {
		this.revenues = revenues;
	}

	@Column(name = "EBITDA", length = 100)
	public double getEbitda() {
		return ebitda;
	}

	public void setEbitda(double ebitda) {
		this.ebitda = ebitda;
	}

	@Column(name = "CASH", length = 100)
	public double getCash() {
		return cash;
	}

	public void setCash(double cash) {
		this.cash = cash;
	}

	@Column(name = "PERCENT_OWNBY_INSIDERS", length = 100)
	public double getPercentOwnbyInsiders() {
		return percentOwnbyInsiders;
	}

	public void setPercentOwnbyInsiders(double percentOwnbyInsiders) {
		this.percentOwnbyInsiders = percentOwnbyInsiders;
	}

	@Column(name = "INST_OWNERSHIP", length = 100)
	public double getInstOwnership() {
		return instOwnership;
	}

	public void setInstOwnership(double instOwnership) {
		this.instOwnership = instOwnership;
	}

	@Column(name = "SHARES_IN_FREEFLOAT", length = 100)
	public double getSharesInFreefloat() {
		return sharesInFreefloat;
	}

	public void setSharesInFreefloat(double sharesInFreefloat) {
		this.sharesInFreefloat = sharesInFreefloat;
	}

	@Column(name = "DEBT", length = 100)
	public double getDebt() {
		return debt;
	}

	public void setDebt(double debt) {
		this.debt = debt;
	}

	@Override
	public boolean equals(Object obj) {
		return (id == ((QuarterlyShareData) obj).getId());
	}

	@ManyToOne
	@JoinColumn(name = "COMPANY_ID")
	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	// added 2014_04_22

	@Column(name = "TOTAL_SHARE_OUTSTAND", length = 100)
	public double getTotShareOutstand() {
		return totShareOutstand;
	}

	public void setTotShareOutstand(double totShareOutstand) {
		this.totShareOutstand = totShareOutstand;
	}

	@Column(name = "EQUITY_TO_SHAREHOLDER", length = 100)
	public double getEquityToSharehol() {
		return equityToSharehol;
	}

	public void setEquityToSharehol(double equityToSharehol) {
		this.equityToSharehol = equityToSharehol;
	}

	@Column(name = "LAST_FOUR_QT_WEIGHTED_AVARAGE", length = 100)
	public double getLstFourQtrWeighted() {
		return lstFourQtrWeighted;
	}

	public void setLstFourQtrWeighted(double lstFourQtrWeighted) {
		this.lstFourQtrWeighted = lstFourQtrWeighted;
	}

	@Column(name = "YEAR", length = 10)
	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	@Column(name = "ADJUSTED_EQUITY_SHAREHOLDER", length = 100)
	public double getAdjestedEquityShareholder() {
		return adjestedEquityShareholder;
	}

	public void setAdjestedEquityShareholder(double adjestedEquityShareholder) {
		this.adjestedEquityShareholder = adjestedEquityShareholder;
	}

	@Column(name = "ADJUSTED_TOTAL_ASSERT", length = 100)
	public double getAdjestedTotalAssets() {
		return adjestedTotalAssets;
	}

	public void setAdjestedTotalAssets(double adjestedTotalAssets) {
		this.adjestedTotalAssets = adjestedTotalAssets;
	}

	@Column(name = "RECURRING_PROFIT", length = 100)
	public double getRecurringNetProfit() {
		return recurringNetProfit;
	}

	public void setRecurringNetProfit(double recurringNetProfit) {
		this.recurringNetProfit = recurringNetProfit;
	}

	@Column(name = "CURRENT_ASSETS", length = 100)
	public double getCurrentAssets() {
		return currentAssets;
	}

	public void setCurrentAssets(double currentAssets) {
		this.currentAssets = currentAssets;
	}

	@Column(name = "CURRENT_LIABILITIES", length = 100)
	public double getCurrentLiability() {
		return currentLiability;
	}

	public void setCurrentLiability(double currentLiability) {
		this.currentLiability = currentLiability;
	}

	/**
	 * get the quater code as Q1, Q2
	 * */
	public String _getQuater() {
		if (quarterCode.length() > 2) {
			return quarterCode.substring(0, 2);
		}

		return quarterCode;
	}

	@Column(name = "LAST_FOUR_RECURRING_PROFIT", length = 100)
	public double getLstFourQtrRecurringProfit() {
		return lstFourQtrRecurringProfit;
	}

	public void setLstFourQtrRecurringProfit(double lstFourQtrRecurringProfit) {
		this.lstFourQtrRecurringProfit = lstFourQtrRecurringProfit;
	}

	public String _getFullQuarterCode() {
		return year + "_" + quarterCode;
	}

}
